	<?php
	// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );

		        $actualPath = dirname(__FILE__) . '/';
		        $actualPath = str_replace('\\', '/', $actualPath);
				$upDir = substr( $actualPath, 0, strrpos( $actualPath, '/') );
				$upDir = substr( $actualPath, 0, strrpos( $upDir, '/') );
				$upDir = substr( $actualPath, 0, strrpos( $upDir, '/') );
				$actualPath = substr( $upDir, 0, strrpos( $upDir, '/') );

				echo "<br /><br />";
				echo "<table border='0' cellpadding='2' cellspacing='1' width='93%' style='font-size: 11px;' align='center'>";
				echo "<tr><td><b>Path: </b>". $actualPath ."</td><td colspan='2' align='center' class='right-col'><b>OwnerShip</b></td><td>&nbsp;</td><td>&nbsp;</td><td colspan='3' align='center'  class='right-col'><b>WebServer</b></td><td>&nbsp;</td></tr>";
				echo "<tr><td class='right-col'><b>Directory</b></td><td align='center' width='50' class='right-col'><b>User</b></td><td align='center' width='50' class='right-col'><b>Group</b></td><td align='center' width='50' class='right-col'><b>Mode</b></td><td width='15'>&nbsp;</td><td align='center' class='right-col' width='50'><b>User</b></td><td align='center' class='right-col' width='50'><b>Group</b></td><td align='center' class='right-col'><b>Read/Write</b></td></tr>";

                $dir = ".";
                $directories = array();
//                $files = array();

                function recursedir($rootdir){
                        $directories = array();
                        $files = array();
                        $dir = (substr($rootdir, -1) == '/') ? substr($rootdir, 0, -1) : $rootdir;

                        if(is_dir($dir)){
                                if($handle = @opendir($dir)){
                                        while(false !== ($file = readdir($handle))){

                                                if($file != "." && $file != ".." && $file !="jts" && $file !=(substr($file, strlen($file) - 4) == '.png') && $file !=(substr($file, strlen($file) - 4) == '.gif') && $file !=(substr($file, strlen($file) - 4) == '.jpg')){
                                                        $filename = $dir.'/'.$file;
                                                        if(is_dir($filename)){
                                                                $folder = $filename;



                                                                $files = array_merge($files, recursedir($filename));

																echo "<tr class='data-container'>";
																	if (substr(sprintf('%o', @fileperms($folder)), -1) == '7') {
																		echo "<td bgcolor='yellow' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'><font color='red'>". $folder."</font></td>";
																	} else {
                                                                		echo "<td style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". $folder."</td>";
																	}

//                                                                echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". fileowner("$folder") ."</td>"; 
//                                                                echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". filegroup("$folder") ."</td>";

                        echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";
                          
//                        $fileowner("$file");
//                        $userinfo = posix_getpwuid($fileowner);
//                        echo "". $userinfo ."";


	$isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	if ($isWin)	{
	  echo fileowner("$folder");
	} else {
	  $folderowneruid=fileowner($folder);
	  $folderownerarray=posix_getpwuid($folderowneruid);
	  $folderowner=$folderownerarray['name']; 
	  	  if ( $folderowner != get_current_user () ) {
  	    echo "<font color=\"#FF9900\">". $folderowner ."</font>";  
	  } else {
	  echo $folderowner;
	  }
	}
echo "</td>"; 
echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";
$isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	if ($isWin)	{
	  echo filegroup("$folder");
	} else {
	  $foldergroupgid=filegroup($folder);
	  $foldergrouparray=posix_getgrgid($foldergroupgid);
	  $foldergroup=$foldergrouparray['name']; 
	  if ( $folderowner != $foldergroup ) {
  	    echo "<font color=\"#FF9900\">". $foldergroup ."</font>";  
	  } else {
	    echo $foldergroup;
	  }
	}
echo "</td>"; 


																	if (substr(sprintf('%o', @fileperms($folder)), -1) == '7') {
																		echo "<td align='center' bgcolor='yellow'  style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;'><font color='red'>";
																	} elseif (substr(sprintf('%o', @fileperms($folder)), -1) <= '4') { 
																		echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;'><font color='blue'>"; 
																	} else { 
																		echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;'><font color='green'>"; 
																	}

																	echo "". substr(sprintf('%o', @fileperms($folder)), -4) ."";
																	echo '</font>';
																	echo "</td>";

																	echo "<td bgcolor='#ffffff'>&nbsp;</td>";

///																$writeable   = '<font color="blue">'. _WRITE .'</font>';
///																$unwriteable = '<font color="green">'. _NOWRITE .'</font>';
///																
///																echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";
///																echo is_writable( $folder )     ? $writeable : $unwriteable;
///																echo "</td>";

echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>";
  $isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	if ($isWin)	{
	  echo getmyuid();
	} else {
	  $webuidowner=getmyuid();
	  $webuidownerarray=posix_getpwuid($webuidowner);
	  $webuidownername=$webuidownerarray['name']; 
	  echo $webuidownername;
	}
echo "</td>";
echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;  border-right: 1px solid #C0C0C0;'>";
  $isWin = (substr(PHP_OS, 0, 3) == 'WIN');
	if ($isWin)	{
	  echo getmygid();
	} else {
	  $webgidgroup=getmygid();
	  $webgidgrouparray=posix_getgrgid($webgidgroup);
	  $webgidgroupname=$webgidgrouparray['name']; 
	  echo $webgidgroupname;
	}
echo "</td>";

//																echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;'>". getmyuid() ."</td>";
//																echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-left: 1px solid #C0C0C0;  border-right: 1px solid #C0C0C0;'>". getmygid() ."</td>";

																$writeable   = '<font color="blue">Writeable</font>';
																$unwriteable = '<font color="green">Read Only</font>';
																
																echo "<td align='center' style='border-bottom: 1px solid #C0C0C0; border-right: 1px solid #C0C0C0;'>";
																echo is_writable( $folder )     ? $writeable : $unwriteable;
																echo "</td>";
																echo "</tr>";
                                                        } else {
                                                                $files[$filename] = filemtime($filename);
                                                        }
                                                }
                                        }
                                        closedir($handle);

                                } else {
                                        die('Could not open directory.' .$folder);
                                }
                        } else {
                                die('Invalid directory.');
                        }
                        return $files;
                }


                $files = recursedir("../");
/*
              if($_GET['sort'] == 'alpha'){
                      if($_GET['mode'] == 'desc'){
                              krsort($files);
                              $highlight = 'alpha_desc';
                      } else {
*/
                                ksort($files);
                                $highlight = 'alpha_asc';
/*
                      }
              } else {
                      if($_GET['mode'] == 'asc'){
                              asort($files, SORT_NUMERIC);
                              $highlight = 'date_asc';
                      } else {
                              arsort($files, SORT_NUMERIC);
                              $highlight = 'date_desc';
                      }
              }
                $sort_alpha_asc = ($highlight == 'alpha_asc') ? '<b>Asc</b>' : '<a href="?option=com_jts&task=jtsdpa&sort=alpha&mode=asc">Asc</a>';
                $sort_alpha_desc = ($highlight == 'alpha_desc') ? '<b>Desc</b>' : '<a href="?option=com_jts&task=jtsdpa&sort=alpha&mode=desc">Desc</a>';
                $sort_date_asc = ($highlight == 'date_asc') ? '<b>Asc</b>' : '<a href="?option=com_jts&task=jtsdpa&sort=date&mode=asc">Asc</a>';
                $sort_date_desc = ($highlight == 'date_desc') ? '<b>Desc</b>' : '<a href="?option=com_jts&task=jtsdpa&sort=date&mode=desc">Desc</a>';
                echo "Sort by: Date- $sort_date_asc | $sort_date_desc; Name- $sort_alpha_asc | $sort_alpha_desc<br />\n<br />\n";
*/

				echo "</table><br><br>";



                ?>




<?php
		$tabs->endTab();
		$tabs->endPane();
?>		